package tile;

import java.io.File;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBException;
import org.thereconstruction.tileset.Tiles;

/**
 * This class enables xml tileset files to be used independantly of java,
 * while backwards compatability means that a default set of tiles can be
 * readily defined using the file "XMLTileSetResourceBundle.properties"
 * 
 * TODO Possibly implement write capabilities here?
 * 
 * @author Sebastian Audet
 */
public class XMLTileSet extends AbstractTileSet {

    public XMLTileSet(String file) {
        this(new File(file));
    }
    
    public XMLTileSet(File file) {
        super();
        super.xmlfile=file;
        if (xmlfile.exists()) {
            try {
                tiles = (Tiles) unmarshaller.unmarshal(xmlfile);
            } catch (JAXBException ex) {
                Logger.getLogger(XMLTileSet.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
    }
    
    public XMLTileSet(URI file) {
        this(new File(file));
    }
    
    @Override
    public int getLevel() {
        return tiles.getLevel().intValue();
    }

}
